<?php


namespace app\common\service\companyIndustry\simulation;

use app\common\service\BaseService;

/**
 * 模拟数据 - 脱硝运行浓度
 */
class SimulationConcentrationService extends BaseService
{
    /**
     * （减排前）根据企业获取模拟企业的不同污染物 运行浓度
     * 注意：排口和企业是一致的
     * @param int $companyId 公司ID
     * @param string $type 污染物类型,eg:SO2/NO2/TSP
     * @return bool|string
     * @throws \Exception
     * @author hongwei 2019-07-16
     */
    public function getBeforeSimulationConcentrationByCompanyId($companyId, $type)
    {
        //step1:根据公司ID为模拟企业
        $sql0 = 'select * from basic_company where id =' . $companyId . ' and realtime_company = 0';
        $sth0 = $this->pdo->prepare($sql0);
        $sth0->execute();
        $data0 = $sth0->fetch();
        if (empty($data0)) {
            exception('该企业不是模拟企业！');
        }

        //step2:查询数据
        $sql = 'select a.* from basic_emission_standards a left join basic_company b on a.industry_id = b.industry_id where b.realtime_company = 0 and  b.id =' . $companyId . ' limit 1';
        $sth = $this->pdo->prepare($sql);
        $sth->execute();
        $data = $sth->fetch();
        if (!$data) {
            return false;
        }

        //step3:根据不同的污染物获取运行浓度
        $result = '';
        if (strtoupper($type) == 'SO2') {
            $result = $data['emission_so2'] / 100;
        }
        if (strtoupper($type) == 'NO2') {
            $result = $data['emission_nox'] / 100;
        }
        if (strtoupper($type) == 'TSP') {
            $result = $data['emission_tsp'] / 100;
        }
        return $result;
    }
    
}